package com.zzty.common;

import com.zzty.entity.SelfExamTransaction;

import java.io.*;

/*** implements Serializable
 * File file = new File("O:\\Java\\com\\jieke\\io\\student.txt");
 *   try
 *   {
 *    file.createNewFile();
 *   }
 *   catch(IOException e)
 *   {
 *    e.printStackTrace();
 *   }
 *   try
 *   {
 *    //Student对象序列化过程
 *    FileOutputStream fos = new FileOutputStream(file);
 *    ObjectOutputStream oos = new ObjectOutputStream(fos);
 *    oos.writeObject(st);
 *    oos.flush();
 *    oos.close();
 *    fos.close();
 *
 *    //Student对象反序列化过程
 *    FileInputStream fis = new FileInputStream(file);
 *    ObjectInputStream ois = new ObjectInputStream(fis);
 *    Student st1 = (Student) ois.readObject();
 *    System.out.println("name = " + st1.getName());
 *    System.out.println("sex = " + st1.getSex());
 *    System.out.println("year = " + st1.getYear());
 *    System.out.println("gpa = " + st1.getGpa());
 *    ois.close();
 *    fis.close();
 */

public class Ser {
    public static void main(String[] args) {
        File file = new File("C:\\temp\\student1.txt");
        SelfExamTransaction set=new SelfExamTransaction();
        set.setId(1);
        set.setAnswerUrl("aaaaaa");
        set.setScore(100);
        set.setSpendTime("1000");
        try {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(set);
            oos.flush();
            oos.close();
            fos.close();

            try (FileInputStream fis = new FileInputStream(file)) {
                ObjectInputStream ois = new ObjectInputStream(fis);
                SelfExamTransaction st1 = (SelfExamTransaction) ois.readObject();

                ois.close();
                fis.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
